//
//  CWStatusViewModel.swift
//  CWWeibo06
//
//  Created by ycw on 2017/7/26.
//  Copyright © 2017年 xiaowei. All rights reserved.
//

import UIKit

/**
 用来处理首页数据显示的viewmodel
 */
class CWStatusViewModel: NSObject {
    
    //static let statuses: CWStatusViewModel = CWStatusViewModel()
    
    var statusModel: CWStatuses? {
        // 在为model模型的时候调用处理图片的方法
        didSet{
            if let currentModel = statusModel {
                
                dealWithmBrankImage(mBrank: currentModel.user?.mbrank ?? 0)
                dealWithVerifiedTypeImage(verfiedType: currentModel.user?.verified_type ?? 0)
                dealWithRetweetContent(status: currentModel)
            }
        }
    }
    
    //处理会员等级图片
    var mbrankImage: UIImage?
    
    //处理微博认证的图片
    var verifiedTypeImage: UIImage?
    
    //处理转发微博的文字内容
    var contentText: String?
    
    fileprivate func dealWithmBrankImage(mBrank: Int) {
        
        if mBrank >= 0 && mBrank <= 6 {
            
            mbrankImage = UIImage(named: "common_icon_membership_level\(mBrank)")
            
        }
    }
    fileprivate func dealWithVerifiedTypeImage(verfiedType: Int) {
        
        switch verfiedType {
        case 0:
            verifiedTypeImage = UIImage(named: "avatar_vip")
        case 2,3,5:
            verifiedTypeImage = UIImage(named: "avatar_enterprise_vip")
        case 220:
            verifiedTypeImage = UIImage(named: "avatar_grassroot")
        default:
            verifiedTypeImage = nil
        }
        
    }
    
    fileprivate func dealWithRetweetContent(status: CWStatuses) {
        
        if status.retweeted_status != nil {
            
            if let name = status.retweeted_status?.user?.screen_name,let text = status.retweeted_status?.text {
                contentText = "@\(name): \(text)"
            }
        }
        
    }
    

}
